package com.caszx.chargingpile.holder.user;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.alibaba.fastjson.JSONException;
import com.app.base.adapter.holder.BaseHolder;
import com.app.base.app.BaseActivity;
import com.app.base.app.BaseNetViewActivity;
import com.app.utils.DiskUser;
import com.caszx.chargingpile.R;
import com.caszx.chargingpile.activity.CommentActivity;
import com.caszx.chargingpile.activity.PayActivity;
import com.caszx.chargingpile.entity.EntityChargeOrder;
import com.caszx.chargingpile.eventbus.OrderPayBus;
import com.caszx.chargingpile.http.ConstantUrl;
import com.caszx.chargingpile.utils.SnackbarHelp;

import org.json.JSONObject;

import java.text.DecimalFormat;
import java.util.HashMap;

import de.greenrobot.event.EventBus;
import http.okhttp.OkHttpUtils;
import http.okhttp.callback.JsonCallback;
import okhttp3.Call;

/**
 * Created by Lihao on 2016/1/30.
 */
public class OrderChargeHolder extends BaseHolder<EntityChargeOrder>  implements View.OnClickListener{

    private TextView txt_station_name;
    private TextView txt_time;
    private TextView btn_comment;

    private DecimalFormat decimalFormat = new DecimalFormat("￥###.##");
    public OrderChargeHolder(View view) {
        super(view);
    }

    @Override
    protected void initView() {
        txt_station_name = (TextView) mRootView.findViewById(R.id.txt_station_name);
        txt_time = (TextView) mRootView.findViewById(R.id.txt_time);
        btn_comment = (TextView) mRootView.findViewById(R.id.btn_comment);
        btn_comment.setOnClickListener(this);
    }

    @Override
    protected void refreshView() {
        txt_station_name.setText(mItem.stationName);
        txt_time.setText(mItem.date+"  "+decimalFormat.format(mItem.totalFees));
        //0、未支付 1、已支付

        if("0".equals(mItem.paystatus)){
            btn_comment.setEnabled(true);
            btn_comment.setText("待支付");
        }else if("1".equals(mItem.paystatus)){
            if("0".equals(mItem.commentstatus )){
                //未评论
                btn_comment.setEnabled(true);
                btn_comment.setText("待评论");
            }else  if("1".equals(mItem.commentstatus )){
                //已评论
                btn_comment.setEnabled(false);
                btn_comment.setText("已评论");
            }
        }

        if("0".equals(mItem.commentstatus )){
            //未评论
            btn_comment.setEnabled(true);
            btn_comment.setText("待评论");
        }else  if("1".equals(mItem.commentstatus )){
            //已评论
            btn_comment.setEnabled(false);
            btn_comment.setText("已评论");
        }

    }

    @Override
    public void onClick(View v) {
        if("0".equals(mItem.paystatus)){
            //待支付
            EventBus.getDefault().post(new OrderPayBus(mItem.ordersId,mPosition));
        }else if("1".equals(mItem.paystatus)){
            if("0".equals(mItem.commentstatus )){
                //未评论
                Intent intent = new Intent(mRootView.getContext(), CommentActivity.class);
                intent.putExtra("ID",mItem.ordersId);
                mRootView.getContext().startActivity(intent);
            }
        }

        if("0".equals(mItem.commentstatus )){
            //未评论
            Intent intent = new Intent(mRootView.getContext(), CommentActivity.class);
            intent.putExtra("ID",mItem.ordersId);
            mRootView.getContext().startActivity(intent);
        }

    }

}
